﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using nplJobsCommon.JobSeeker;
using nplJobs.DB;
using System.Data;
using nplJobsCommon.Common;
using nplJobsCommon;

namespace nplJobsDAL.Select
{
    public class SelectSavedJobs
    {
        public static List<JobListDetails> GetList(int id)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@userID", id, DbType.Int32));

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spSelectSavedJobs");

                List<JobListDetails> results = new List<JobListDetails>();
                foreach (DataRow dr in dt.Rows)
                {
                    JobListDetails objJobList = new JobListDetails();

                    MapperBase.GetInstance().MapItem(objJobList, dr); ;
                    results.Add(objJobList);
                }
                return results;

            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static SavedJob GetSavedJobsByJobId(int jobId, Guid jobSeekerId)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@JobID", jobId, DbType.Int64));
                cpList.Add(new CustomParameter("@JobSeekerID", jobSeekerId, DbType.Guid));

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spSelectSavedJobsByJobId");

                SavedJob results = null;
                foreach (DataRow dr in dt.Rows)
                {
                    results = new SavedJob();
                    MapperBase.GetInstance().MapItem(results, dr);
                }
                return results;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}
